package com.ruibang.glass.produce.controller.system;

import com.ruibang.glass.produce.entity.TypeUnit;
import com.ruibang.glass.produce.service.UnitService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author SongJinKang
 * @version 1.0.0
 * @ClassName UnitController.java
 * @Description TODO
 * @createTime 2021年01月16日 13:56:00
 */

@Slf4j
@Api(tags = "单位接口")
@RequestMapping("/api/glass/produce/unit")
@RestController
public class UnitController {


    @Autowired
    private UnitService unitService;

    @GetMapping("all")
    @ApiOperation(value = "获取全部单位列表", response = ResultBody.class)
    public ResultBody allTypeUnit() {
        return unitService.allTypeUnit();
    }

    @PutMapping("update")
    @ApiOperation(value = "跟新单位", response = ResultBody.class)
    public ResultBody updateUnit(@RequestBody List<TypeUnit> units) {
        unitService.updateUnit(units);
        return ResultBody.success();
    }

    @DeleteMapping("delete/{unitId}")
    @ApiOperation(value = "删除一个单位", response = ResultBody.class)
    public ResultBody deleteUnit(@PathVariable String unitId) {
        return unitService.deleteById(unitId);
    }

    @PostMapping("save")
    @ApiOperation(value = "保存一个单位", response = ResultBody.class)
    public ResultBody saveUnit(@RequestBody TypeUnit unit) {
        unitService.save(unit);
        return ResultBody.success();
    }

}
